package com.ls.lserp.modules.job.web;

import java.sql.SQLException;
import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;

import com.ls.lserp.common.dynamicsource.DataSourceContextHolder;
import com.ls.lserp.common.utils.DateUtils;
import com.ls.lserp.common.utils.SpringContextHolder;
import com.ls.lserp.common.web.BaseController;
import com.ls.lserp.modules.job.service.MaterialAlertService;
import com.ls.lserp.modules.setting.entity.InventoryWarning;

/**
 * @ClassName: AccountingJob
 * @Description: 原辅料预警控制层
 * 
 * @author 于辉
 * @date 2017年03月13日
 *
 */
public class MaterialAlertJob extends BaseController {

	// 保存 编辑 删除 方法
	@Autowired
	private MaterialAlertService materialAlertService = SpringContextHolder.getBean(MaterialAlertService.class);;

	/**
	 * @throws SQLException
	 * @Title: 需要采购的原辅料的明细数据插入
	 */
	public void reserveSelectInsert() throws Exception {
		// 切换ERP数据库
		DataSourceContextHolder.setDbType(DataSourceContextHolder.DATA_SOURCE_ZYSQL);
		// System.out.println(DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
		// System.out.println("云云");
		// 获取开始日期时间
		String nowDateTime = DateUtils.getDateTime();

		logger.info("--------------------" + nowDateTime + "需要采购的原辅料的明细数据batch开始------------------------");

		InventoryWarning inventoryWarning = new InventoryWarning();
		Calendar calendar = Calendar.getInstance();// 此时打印它获取的是系统当前时间
		calendar.add(Calendar.DATE, -1); // 得到前一天
		inventoryWarning.setDateTime(calendar.getTime());
		// System.out.println(new
		// SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()));
		materialAlertService.insertMaterialAlertReserve(inventoryWarning);

		nowDateTime = DateUtils.getDateTime();

		logger.info("--------------------" + nowDateTime + "需要采购的原辅料的明细数据batch结束------------------------");
	}

}
